<?php

namespace fztadmin\modules\platform\models\searches;

use yii\base\Model;

class FundTransactionDetailsFilter extends Model
{
    public $begin_date;
    public $end_date;

    public function init()
    {
        parent::init();
        if (!$this->end_date) {
            $this->end_date = date("Ymd");
        }
        if (!$this->begin_date) {
            $this->begin_date = date("Ymd", strtotime($this->end_date) - 86400 * 90);
        }
    }

    public function attributeLabels()
    {
        return [
            'begin_date' => "开始日期",
            'end_date' => "结束日期",
        ];
    }

    public function rules()
    {
        return [
            [['begin_date', 'end_date'], 'trim'],
            [['begin_date', 'end_date'], 'checkDate'],
        ];
    }

    public function checkDate($attribute, $params)
    {
        $reg = "/^\d{4}\d{2}\d{2}$/";
        $v = $this->$attribute;
        if (!preg_match($reg, $v)) {
            $this->addError($attribute, "输入的日期格式错误");
        }
    }
}